using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml;
using Barbar.MapReport.Common;

namespace Barbar.MapReport.HtmlRender.Shapes {
  internal class CircleShape : Shape, IShape {
    private Color m_Color;

    public Color Color {
      get { return m_Color; }
      set { m_Color = value; }
    }

    public CircleShape() {
    }

    public CircleShape(int radius, Color color) : base(radius * 2, radius * 2)  {
      m_Color = color;
    }

    public override void Draw(System.Drawing.Graphics graphics) {
      graphics.FillEllipse(new SolidBrush(m_Color), Rectangle);
      graphics.DrawEllipse(new Pen(Color.Black), Rectangle);
    }

    #region IXmlSerializable Members

    public override void ReadXml(XmlReader reader) {
      reader.Read();
      if (reader.NodeType != XmlNodeType.Element || reader.Value == "cs")
        throw new MapReportException("Excepted 'cs'");
      base.ReadXml(reader);
      Color = System.Drawing.Color.FromArgb(XmlConvert.ToInt32(reader.GetAttribute("c")));
    }

    public override void WriteXml(XmlWriter writer) {
      writer.WriteStartElement("cs");
      base.WriteXml(writer);
      writer.WriteAttributeString("c", XmlConvert.ToString(Color.ToArgb()));
      writer.WriteEndElement();
    }

    #endregion
  }
}
